package com.kx.springboot.controller;

import com.kx.springboot.bean.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/user")
public class UserController {
    @RequestMapping("/login")
    public Object login(HttpServletRequest request){
        User user=new User();
        user.setId(1);
        user.setUsername("zkx");
        request.getSession().setAttribute("user",user);
        System.out.println("login");
        return "Login Success";
    }
    //该请求需要用户登录才能访问
    @RequestMapping("/center")
    public Object center(){
        return "See Center Msg";
    }
    //用户未登录也能访问
    @RequestMapping("/out")
    public Object out(){
        return "Out See Anytime";
    }
    //用户未登录访问需要登录才能访问的信息
    @RequestMapping("/error")
    public Object error(){
        return "error";
    }
}
